﻿package plugin.chatflash.controller
{
    import __AS3__.vec.*;
    import cmd.*;
    import com.core.*;
    import com.sh.game.consts.*;
    import com.sh.game.net.*;
    import consts.*;
    import flash.utils.*;
    import plugin.chatflash.model.*;
    import pluginfw.*;

    public class ChatChannelBase extends Object
    {
        private var mChannelID:int = 0;
        public var mMaxCount:int = 50;
        private var mCDTime:int = 0;
        private var mSendTime:int = 0;
        private var mMsgList:Vector.<ChatVO>;
        private const SEPARATE:String = "#!";

        public function ChatChannelBase(param1:int = 0, param2:int = 0)
        {
            this.mChannelID = param1;
            this.mCDTime = param2;
            this.mMsgList = new Vector.<ChatVO>;
            return;
        }// end function

        public function sendMsg(param1:ChatVO) : void
        {
            var _loc_3:Array = null;
            var _loc_5:Object = null;
            var _loc_6:int = 0;
            var _loc_7:String = null;
            var _loc_8:int = 0;
            var _loc_9:Object = null;
            var _loc_10:Array = null;
            var _loc_11:Object = null;
            var _loc_12:int = 0;
            var _loc_2:* = getTimer() / 1000;
            if (param1.Type == 2)
            {
                if (this.mCDTime != 3)
                {
                    _loc_5 = UserData.getUserData();
                    if (_loc_5.rein > 0 || _loc_5 >= 70)
                    {
                        this.mCDTime = 3;
                    }
                }
            }
            if (this.mSendTime > 0 && _loc_2 - this.mSendTime < this.mCDTime)
            {
                _loc_6 = this.mSendTime + this.mCDTime - _loc_2;
                _loc_7 = "";
                if (param1.Type == ChatCMD.ChannelShop)
                {
                    _loc_7 = StringUtil.substitute("{0}秒后可展示", _loc_6);
                }
                else
                {
                    _loc_7 = StringUtil.substitute("还需要{0}秒可以发送消息", _loc_6);
                }
                ModelProxy.change("movetips", "error", _loc_7);
                return;
            }
            this.mSendTime = _loc_2;
            param1.TalkContent = param1.TalkContent.replace(/\\\r""\\r/g, "");
            if (param1.Type == ChatCMD.ChannelPrivate)
            {
                param1.TalkContent = param1.TalkContent.replace(/#!""#!/g, "#*!");
                _loc_3 = [param1.RoleID, param1.RoleName, param1.RoleVip, param1.ToRoleID, param1.ToRoleName, param1.TeamID, param1.UnionID, param1.TalkContent, param1.sex, param1.career, param1.rein, param1.level, param1.title, param1.itemList, param1.msgToAnnounce];
            }
            else if (param1.Type == ChatCMD.ChannelUnion)
            {
                _loc_3 = [param1.RoleID, param1.RoleName, param1.RoleVip, param1.ToRoleID, param1.ToRoleName, param1.TeamID, param1.UnionID, param1.TalkContent, param1.sex, param1.career, param1.title, param1.itemList, param1.msgToAnnounce];
            }
            else
            {
                _loc_3 = [param1.RoleID, param1.RoleName, param1.RoleVip, param1.ToRoleID, param1.ToRoleName, param1.TeamID, param1.UnionID, param1.TalkContent, param1.title, param1.itemList, param1.msgToAnnounce];
            }
            var _loc_4:* = _loc_3.join(this.SEPARATE);
            if (param1.Type == ChatCMD.ChannelTeam)
            {
                _loc_8 = UserData.getUserData("teamid");
                if (_loc_8 > 0)
                {
                    Server.instance.send(113, 100, _loc_4, 0, ConnectType.SYSTEM);
                }
                return;
            }
            if (param1.Type == ChatCMD.ChannelStage)
            {
                _loc_9 = ModelProxy.getValue("data", "updateMap");
                _loc_10 = [];
                for each (_loc_11 in _loc_9)
                {
                    
                    if (_loc_11.rid > 10000 && _loc_11.type == ActorType.Actor)
                    {
                        _loc_10.push(_loc_11.rid);
                    }
                }
                if (_loc_10.length > 0)
                {
                    Server.instance.send(110, param1.Type, [_loc_4, _loc_10], 0, ConnectType.SYSTEM);
                }
                return;
            }
            if (param1.Type == ChatCMD.ChannelUnion)
            {
                _loc_12 = UserData.getUserData("unionid");
                if (_loc_12 == 0)
                {
                    ModelProxy.change("movetips", "error", "你当前没有行会");
                    return;
                }
            }
            Server.instance.send(110, param1.Type, _loc_4, 0, ConnectType.SYSTEM);
            return;
        }// end function

        public function receiveMsg(param1:ChatVO) : void
        {
            this.mMsgList.push(param1);
            if (this.mMsgList.length > this.mMaxCount)
            {
                this.mMsgList.shift();
            }
            return;
        }// end function

        public function get msgList() : Vector.<ChatVO>
        {
            return this.mMsgList;
        }// end function

        public function get channelID() : int
        {
            return this.mChannelID;
        }// end function

    }
}
